package com.ql.gamelogm.controller;

import com.ql.gamelogm.entities.CalendarEvent;
import com.ql.gamelogm.service.CalendarService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
public class CalendarController {
    @Autowired
    private CalendarService calendarService;
    @RequestMapping(value = "/findCalsById")
    @ResponseBody
    public List<CalendarEvent> findCalsById(HttpSession httpSession){
        String id =(String) httpSession.getAttribute("id");
        List<CalendarEvent> calendarEventList = calendarService.findCalsById(id);
        for(int i=0;i<calendarEventList.size();i++){
            System.out.println(calendarEventList.get(i).toString());
        }
        return calendarEventList;
    }
    @RequestMapping(value = "/updateCalsById")
    public String updateCalsById(HttpServletRequest request,HttpSession httpSession){
        String id =(String) httpSession.getAttribute("id");
        String date=request.getParameter("date");
        String content=request.getParameter("content");
        calendarService.updateCalsById(date,id,content);

        return "calendar";
    }
    @RequestMapping(value = "/addCals")
    @ResponseBody
    public String addCals(HttpServletRequest request,HttpSession httpSession){
        String id =(String) httpSession.getAttribute("id");
        String date=request.getParameter("date");
        String content=request.getParameter("content");
        calendarService.addCals(date,id,content);
        return "calendar";
    }
}
